import java.util.regex.Pattern;


public class StringDemo {

	public static void main(String[] args) {
		String source = " hello world! ";
		
		// 进行字符串替换
		String result1 = source.replace("hello", "goodbye");
		System.out.println(result1);
		// 正则表达式替换(字面量正则)
		String result2 = source.replaceAll(Pattern.compile("hello",Pattern.LITERAL).pattern(), "*");
		System.out.println(result2);
		// 正则表达式替换
		String result3 = source.replaceAll(Pattern.compile("\\s").pattern(), "*");
		System.out.println(result3);
		// 正则表达式替换
		String result4 = source.replaceAll("\\s", "*");
		System.out.println(result4);
		
	}
}
